<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>发货单提交</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-formNo">表单编号</label>
                                    <input id="query-formNo" type="text" name="formNo" class="form-control"
                                           placeholder="请输入表单编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-orderform">发货编号</label>
                                    <input id="query-orderform" type="text" name="orderform" class="form-control"
                                           placeholder="请输入发货编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-driverName">司机电话</label>
                                    <input id="query-driverName" type="text" name="driverName" class="form-control"
                                           placeholder="请输入司机电话">
                                </div>
                                <div class="form-group">
                                    <label for="query-driverNum">车牌号</label>
                                    <input id="query-driverNum" type="text" name="driverNum" class="form-control"
                                           placeholder="请输入车牌号">
                                </div>
                                <div class="form-group">
                                    <label for="query-subStatus">提交状态</label>
                                    <select id="query-subStatus" class="form-control" name="subStatus">
                                        <option value="" >全部</option>
                                        <option value="2" selected="selected">未提交</option>
                                        <option value="1">已提交</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-startTime">发货日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker"
                                           name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;
    $(function () {

        table = js.table.init({
            url: ctx + "shipments/shipmentsList",
            showExport: false,
            columns: [
                {
                    title: '序号', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "表单编号", field: 'formNo'},
                {title: "发货编号", field: 'orderform'},
                {title: "项目名称", field: 'proName'},
                {title: "开票名头", field: 'invoice'},
                {title: "发货人及联系电话", field: 'consignor'},
                {title: "收货人及联系电话", field: 'consignee'},
                {title: "发货地址", field: 'setAddress'},
                {title: "收货地址", field: 'getAddress'},
                {title: "发货日期", field: 'setTime'},
                {title: "司机电话", field: 'driverName'},
                {title: "挂车种类", field: 'trailer'},
                {
                    title: "提交状态", field: 'subStatus',
                    formatter: function (value) {
                        if (value==2){
                            return '<span class="badge label-default">未提交</span>';
                        }
                        if (value==1){

                            return '<span class="badge label-success">已提交</span>';
                        }
                    }
                },
                {
                    title: "操作",
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a class="btn btn-info btn-xs" target="_blank"   href="' + ctx + 'shipments/listSelect/' + row.id + '" > 查看</a>');
                        if (row.subStatus==1){
                            actions.push('<a class="btn btn-danger btn-xs" shiro:hasPermission="conInstall:list:regit" onclick="updateStaus(' + row.id + ')" > 撤销</a> ');
                        }
                        if (row.subStatus==2){
                            actions.push('<a class="btn btn-warning btn-xs" shiro:hasPermission="conInstall:list:edit"  href="' + ctx + 'shipments/listEdit/' + row.id + '" > 编辑</a> ');
                            actions.push('<a class="btn btn-success btn-xs" shiro:hasPermission="conInstall:list:submit" onclick="submit(' + row.id + ')" > 提交</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" shiro:hasPermission="conInstall:list:del" onclick="del(' + row.id + ')" > 删除</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        });
    });


    /** 删除 */
    function del(id) {
        js.modal.confirm("确定要删除吗？", function () {
            js.post({
                url: ctx + "shipments/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
    /** 提交 */
    function submit(id) {
        js.modal.confirm("确定要提交吗？", function () {
            js.post({
                url: ctx + "shipments/submit",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
    /** 撤销提交 */
    function updateStaus(id) {
        js.modal.confirm("确定要改为未提交吗？", function () {
            js.post({
                url: ctx + "shipments/updateStaus",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
</script>
</body>
</html>
